package com.pc.scrs.controller;

import com.pc.scrs.bean.vo.UsersVo;
import com.pc.scrs.service.IUsersService;
import com.pc.scrs.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/users")
public class UsersController {

    @Resource
    private IUsersService usersService;

    @GetMapping("/info")
    public ResponseResult getUserInfo(HttpServletRequest request){
        String jwtToken = request.getHeader("jwtToken");
        UsersVo userInfo = usersService.userInfo(jwtToken);
        if(userInfo!=null){
            return new ResponseResult(200, "ok",userInfo);
        }else {
            return ResponseResult.FAIL;
        }
    }
    @GetMapping("/updatePassword")
    public ResponseResult updatePassword(HttpServletRequest request,String password){
        String jwtToken = request.getHeader("jwtToken");
        Integer result = usersService.updatePassword(jwtToken,password);
        return new ResponseResult(200, "ok",result);
    }

    @GetMapping("/updateInfo")
    public ResponseResult updateInfo(HttpServletRequest request,String name,String sign){
        String jwtToken = request.getHeader("jwtToken");
        Integer result = usersService.updateInfo(jwtToken,name,sign);
        return new ResponseResult(200, "ok",result);
    }


}
